//
//  CasesCell.m
//  KurtulusLaw
//
//  Created by phuc phuc on 12/1/12.
//  Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//

#import "CasesCell.h"
#import "KCaseDTO.h"

@implementation CasesCell
@synthesize videoImageButton;

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)setSearchFileDTO:(KBaseSearchFileDTO *)searchFile {
	[super setSearchFileDTO:searchFile];
	
	if ([searchFile isKindOfClass:[KCaseDTO class]]) {
		KCaseDTO *caseDTO = (KCaseDTO *)searchFile;
				
		if (caseDTO.fileVideo && [caseDTO.fileVideo length] > 0) {
			[self.videoImageButton setImage:[UIImage imageNamed:kIconConvertingVideo] forState:UIControlStateNormal];
			[self.videoImageButton setHidden:NO];
			self.videoImageButton .tag = eFileTypeConvertingVideo;
		} else {
			[self.videoImageButton setHidden:YES];
		}
		
		if (caseDTO.fileMp4 && [caseDTO.fileMp4 length] > 0) {
			[self.videoImageButton setImage:[UIImage imageNamed:kIconConvertedVideo] forState:UIControlStateNormal];
			[self.videoImageButton setHidden:NO];
			self.videoImageButton.tag = eFileTypeConvertedVideo;
		} else {
			[self.videoImageButton setHidden:YES];
		}
	}
}

- (IBAction)touchInsidePDFImageButton:(id)sender {
	if (self.delegate) {
		[self.delegate searchFileCell:self clickDocumentFile:eFileTypePDF relativePath:[self.searchFileDTO.filePDF copy]];
	}
}

- (IBAction)touchInsideVideoImageButton:(id)sender {
	if (self.delegate) {
		KCaseDTO *caseDTO = (KCaseDTO *)self.searchFileDTO;
		NSString *filePath = self.videoImageButton.tag == eFileTypeConvertedVideo? caseDTO.fileMp4 : caseDTO.fileVideo;
		[self.delegate searchFileCell:self clickDocumentFile:self.videoImageButton.tag relativePath:[filePath copy]];
	}
}
@end
